import 'dart:async';

import 'package:flutter/material.dart' hide Action;

import 'package:flutter_lui/flutter_lui.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: const HomePage(),
      navigatorObservers: [LNavigatorObserver()],
    );
  }
}

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  State<StatefulWidget> createState() => _HomePage();
}

class _HomePage extends State<HomePage> {
  String inputValue1 = '默认内容';
  String inputValue2 = '默认内容2';
  int badgeNum = 10;
  bool checked = false;
  String wheelValue = '4';
  LDialogController? dialogController;
  TextEditingController controller = TextEditingController();
  double progressValue = 0.5;
  int select = 2;
  LCarouselController? carouselController;
  List<int> lcarouserData = [1, 2, 3, 4, 5];
  String toastValue = '默认内容';

  OverlayEntry? overlayEntry;
  handleRun() async {
    toastValue = '${toastValue}1';
    LToast.show(
      message: toastValue,
    );
    // await delay(1000);
    // Navigator.push(
    //     context, MaterialPageRoute(builder: (_) => const SecondPage()));

    // var res = await LDialog.showConfirmDialog(context, crossPage: false,
    //     child: OverlayEntryWidget(
    //   onTapNext: () {
    //     Navigator.push(
    //         context, MaterialPageRoute(builder: (_) => const SecondPage()));
    //   },
    // ));
    // print(res);
  }

  handleTest() async {
    print(overlayEntry);
    overlayEntry ??=
        OverlayEntry(builder: (_) => OverlayEntryWidget(onTapNext: handleRun));
    OverlayState overlayState = Overlay.of(context);
    overlayState.insert(overlayEntry!);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
        floatingActionButton: LFlowNavigationBar(
            itemWidth: 50,
            expandRadius: PageSize.width / 2 - 50,
            backgroundColor: LUI.instance.successColor,
            direction: LFlowNavigationExpandDirection.left,
            onChange: ((index) => print(index)),
            mainItem: const Icon(
              Icons.abc,
              size: 30,
              color: Colors.white,
            ),
            items: const [
              Icon(
                Icons.access_alarm_outlined,
                size: 30,
                color: Colors.white,
              ),
              Icon(
                Icons.access_alarm_outlined,
                size: 30,
                color: Colors.white,
              ),
              Icon(
                Icons.abc_rounded,
                size: 30,
                color: Colors.white,
              ),
              Icon(
                Icons.ac_unit_rounded,
                size: 30,
                color: Colors.white,
              ),
              Icon(
                Icons.access_alarm_rounded,
                size: 30,
                color: Colors.white,
              ),
            ]),
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: SingleChildScrollView(
          padding: EdgeInsets.all(rpx(10)),
          child: Column(
            children: [
              const LText('显示一行文字'),
              Container(height: 10),
              const LText(
                '显示二行文字显示二行文字显示二行文字显示二行文字显示二行文字显示二行文字显示二行文字显示二行文字显示二行文字显示二行文字',
                maxLines: 2,
                overflow: TextOverflow.ellipsis,
              ),
              LButton(
                text: '执行',
                onTap: handleRun,
                marginVertical: rpx(10),
              ),
              LButton(
                  text: 'progress',
                  shape: LButtonShape.round,
                  backgroundColor: Colors.pink,
                  outline: false,
                  onTap: () {
                    setState(() {
                      progressValue -= 0.1;
                    });
                  }),
              Container(height: 40),
              LProgress(
                value: progressValue,
                // disabled: true,
                onChange: (v) => setState(() {
                  progressValue = v;
                }),
              ),
              Container(height: 10),
              LCarousel(
                // autoPlay: false,
                onCreated: (v) {
                  carouselController = v;
                  v.jumpTo(3);
                },
                dotIndicatorConfig: LIndicatorConfig(
                  dotWidth: rpx(8),
                  dotHeight: rpx(8),
                  dotRadius: rpx(8),
                  dotWidthChanged: false,
                  // height: rpx(40),
                  backgroundColor: LUI.instance.successColor.withOpacity(0.5),
                ),
                children: lcarouserData
                    .map((e) => LBox(
                          backgroundColor: Colors.green.withOpacity(0.3),
                          child: e,
                          alignment: Alignment.center,
                        ))
                    .toList(),
              ),
              LBox(
                direction: BoxDirections.horizontal,
                children: [
                  LButton(
                    text: '上一页',
                    onTap: () {
                      if (carouselController != null) {
                        carouselController!.prev();
                      }
                    },
                  ),
                  LButton(
                    text: '下一页',
                    onTap: () {
                      if (carouselController != null) {
                        carouselController!.next();
                      }
                    },
                  ),
                  LButton(
                    text: '第2页',
                    onTap: () {
                      if (carouselController != null) {
                        carouselController!.jumpTo(2);
                      }
                    },
                  ),
                  LButton(
                    text: '换数据1',
                    onTap: () {
                      setState(() {
                        lcarouserData = [11, 22, 33, 4, 5, 6, 7, 8, 9, 10];
                      });
                    },
                  ),
                  LButton(
                    text: '换数据2',
                    onTap: () {
                      setState(() {
                        lcarouserData = [111, 222, 333, 44, 55, 6];
                      });
                    },
                  )
                ],
              ),
              Container(height: 10),
              LButton(
                width: 140,
                shape: LButtonShape.round,
                text: 'picker',
                onTap: () async {
                  var res = await LPicker.showPicker(
                      title: '请选择一项',
                      value: '12',
                      items: [
                        LPickerItem(
                            label: '第一项第一项第一项第一项第第一项第一项第一项第一项第一项', value: '1'),
                        LPickerItem(label: '第二项', value: '2'),
                        LPickerItem(label: '第三项', value: '3'),
                        LPickerItem(label: '1第一项', value: '11'),
                        LPickerItem(label: '1第二项', value: '12'),
                        LPickerItem(label: '1第三项', value: '13'),
                        LPickerItem(label: '2第一项', value: '21'),
                        LPickerItem(label: '2第二项', value: '22'),
                        LPickerItem(label: '2第三项', value: '23'),
                        LPickerItem(label: '3第一项', value: '31'),
                        LPickerItem(label: '3第二项', value: '32'),
                        LPickerItem(label: '3第三项', value: '33'),
                      ]);
                  if (res == 0) return;
                  LColorPrint.magenta(
                      '你选择的是${(res as LPickerItem).label}项 value=${res.value} index=${res.index}');
                },
              ),
              Container(height: 10),
              LButton(
                width: 140,
                shape: LButtonShape.round,
                text: 'multiPicker',
                onTap: () async {
                  var res =
                      await LPicker.showMultiPicker(title: '请选择一项', values: [
                    '1',
                    '12',
                    '123',
                    '1234'
                  ], items: [
                    LMultiPickerItem(label: '第一列1', value: '1', children: [
                      LMultiPickerItem(label: '第二列11', value: '11', children: [
                        LMultiPickerItem(
                            label: '第三列111',
                            value: '111',
                            children: [
                              LMultiPickerItem(label: '第四列1111', value: '1111'),
                              LMultiPickerItem(label: '第四列1112', value: '1112'),
                              LMultiPickerItem(label: '第四列1113', value: '1113'),
                              LMultiPickerItem(label: '第四列1114', value: '1114'),
                            ]),
                        LMultiPickerItem(
                            label: '第三列112',
                            value: '112',
                            children: [
                              LMultiPickerItem(label: '第四列1121', value: '1121'),
                              LMultiPickerItem(label: '第四列1122', value: '1122'),
                              LMultiPickerItem(label: '第四列1123', value: '1123'),
                              LMultiPickerItem(label: '第四列1124', value: '1124'),
                            ]),
                        LMultiPickerItem(
                            label: '第三列113',
                            value: '113',
                            children: [
                              LMultiPickerItem(label: '第四列1131', value: '1131'),
                              LMultiPickerItem(label: '第四列1132', value: '1132'),
                              LMultiPickerItem(label: '第四列1133', value: '1133'),
                              LMultiPickerItem(label: '第四列1134', value: '1134'),
                            ]),
                        LMultiPickerItem(
                            label: '第三列114',
                            value: '114',
                            children: [
                              LMultiPickerItem(label: '第四列1141', value: '1141'),
                              LMultiPickerItem(label: '第四列1142', value: '1142'),
                              LMultiPickerItem(label: '第四列1143', value: '1143'),
                              LMultiPickerItem(label: '第四列1144', value: '1144'),
                            ]),
                      ]),
                      LMultiPickerItem(label: '第二列12', value: '12', children: [
                        LMultiPickerItem(
                            label: '第三列121',
                            value: '121',
                            children: [
                              LMultiPickerItem(label: '第四列1211', value: '1211'),
                              LMultiPickerItem(label: '第四列1212', value: '1212'),
                              LMultiPickerItem(label: '第四列1213', value: '1213'),
                              LMultiPickerItem(label: '第四列1214', value: '1214'),
                            ]),
                        LMultiPickerItem(
                            label: '第三列122',
                            value: '122',
                            children: [
                              LMultiPickerItem(label: '第四列1221', value: '1221'),
                              LMultiPickerItem(label: '第四列1222', value: '1222'),
                              LMultiPickerItem(label: '第四列1223', value: '1223'),
                              LMultiPickerItem(label: '第四列1224', value: '1224'),
                            ]),
                        LMultiPickerItem(
                            label: '第三列123',
                            value: '123',
                            children: [
                              LMultiPickerItem(label: '第四列1231', value: '1231'),
                              LMultiPickerItem(label: '第四列1232', value: '1232'),
                              LMultiPickerItem(label: '第四列1233', value: '1233'),
                              LMultiPickerItem(label: '第四列1234', value: '1234'),
                            ]),
                        LMultiPickerItem(
                            label: '第三列124',
                            value: '124',
                            children: [
                              LMultiPickerItem(label: '第四列1241', value: '1241'),
                              LMultiPickerItem(label: '第四列1242', value: '1242'),
                              LMultiPickerItem(label: '第四列1243', value: '1243'),
                              LMultiPickerItem(label: '第四列1244', value: '1244'),
                            ]),
                      ]),
                    ]),
                  ]);
                  if (res == 0) return;
                  for (var item in (res as List<LMultiPickerItem>)) {
                    LColorPrint.magenta(
                        '你选择的是${item.label}项 value=${item.value} index=${item.index}');
                  }
                },
              ),
              Container(height: 10),
              LButton(
                width: 140,
                shape: LButtonShape.round,
                text: '按钮',
                onTap: () async {
                  LLoadingMask.show(tips: '加载中...');
                  await delay(1000);
                  setState(() {
                    badgeNum += 9;
                    select = 1;
                    wheelValue = wheelValue == '4' ? '9' : '4';
                  });
                  LLoadingMask.hide();
                },
              ),
              Container(height: 10),
              LCircleButtonTabbar(
                  select: select,
                  items: const ['第一项', '第二项', '第三项', '第四项'],
                  width: PageSize.width - rpx(20),
                  height: 40),
              Container(height: 10),
              LBox(
                backgroundColor: Colors.green.withAlpha(75),
                child: LInput(
                  padding: [rpx(10)],
                  isDense: true,
                  value: inputValue1,
                  hintText: '默认使用',
                  hintColor: Colors.green,
                  formater: [RegExp(r'^[0-9]{1,}[\.]?[0-9]{0,}')],
                  maxLines: 2,
                  // numberKeyboard: true,
                  onChange: (v) => setState(() {
                    inputValue1 = v;
                  }),
                  onBlur: (v) {
                    setState(() {
                      inputValue1 = '${v}1';
                    });
                  },
                ),
              ),
              const LDivider(
                color: Colors.green,
                textPosition: LDividerTextPosition.center,
              ),
              LPasswordGrid(
                gridLimit: 7,
                onChange: (v) => print('onChange $v'),
                onComplete: (v) => print('onComplete $v'),
              ),
              const LDivider(
                color: Colors.green,
                textPosition: LDividerTextPosition.center,
              ),
              LBox(
                child: LInput(
                  controller: controller,
                  hintText: '可清空内容',
                  isDense: false,
                  value: inputValue2,
                  hintColor: Colors.green,
                  suffixIcon: GestureDetector(
                    child: const Icon(Icons.clear_rounded),
                    onTap: () {
                      setState(() {
                        inputValue2 = '';
                        controller.text = '';
                      });
                    },
                  ),
                  onChange: (v) => setState(() {
                    inputValue2 = v;
                  }),
                ),
              ),
              Container(height: 10),
              LImage(
                  radius: 10,
                  height: 60,
                  width: PageSize.width - 20,
                  fit: BoxFit.fill,
                  img:
                      'https://kgj-card.oss-cn-shanghai.aliyuncs.com/2024/01/03/53804b2bd44c4638953fa0b4f255378f.jpg'),
              const LDivider(),
              LBox(
                height: rpx(80),
                backgroundColor: Colors.green,
                alignment: Alignment.center,
                child: LBadges(
                  count: 10, // badgeNum,
                  // type: LBadgeType.dot,
                  // dotWidth: rpx(30),
                  fontSize: rpx(10),
                  child: const LBox(
                    backgroundColor: Colors.red,
                    width: 40,
                    alignment: null,
                    child: '徽标',
                  ),
                ),
              ),
              const LDivider(),
              LBox(
                borderRadius: const [10],
                backgroundImage:
                    'https://kgj-card.oss-cn-shanghai.aliyuncs.com/2024/01/03/53804b2bd44c4638953fa0b4f255378f.jpg',
                child: LBox(
                  height: 100,
                  glassFilter: 10,
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  direction: BoxDirections.horizontal,
                  children: [
                    LPopover(
                        popWidth: 100,
                        label:
                            'labellabellabellabellabellab\nellabellabellabellabel',
                        child: const LBox(
                          backgroundColor: Colors.green,
                          child: '1111111',
                        )),
                    LPopover(
                        popWidth: 130,
                        position: LPopoverPosition.bottom,
                        label:
                            'labellabellabellabellabellab\nellabellabellabellabel',
                        child: const LBox(
                          backgroundColor: Colors.green,
                          child: '222222',
                        )),
                    LPopover(
                        position: LPopoverPosition.bottom,
                        label:
                            'labellabellabellabellabellab\nellabellabellabellabel',
                        child: const LBox(
                          backgroundColor: Colors.green,
                          child: '3333333',
                        )),
                  ],
                ),
              ),
              LBox(
                direction: BoxDirections.horizontal,
                children: [
                  LCheckBox(
                    marginRight: 30,
                    marginTop: rpx(10),
                    value: checked,
                    color: LUI.instance.dangerColor,
                    onChange: (v) {
                      setState(() {
                        checked = v;
                      });
                    },
                  ),
                  LRadio(
                    value: checked,
                    onChange: (v) {
                      setState(() {
                        checked = v;
                      });
                    },
                  )
                ],
              ),
              LSwitch(
                shape: LSwitchShape.circle,
                value: checked,
                activeText: '开嘎嘎嘎',
                inactiveText: '关关关关',
                onChange: (v) {
                  var a = LDay();
                  print(a.format('YYYYYMMMDDD HHHmmmsss'));
                  var str = '二零二四年三月二十八日 三十二点十二分十二秒十二毫秒十二微秒';
                  print(LDay.fromString(str)
                      .format('YYYY-MM-DD HH:mm:ss.SSSSWS'));

                  setState(() {
                    checked = v;
                  });
                },
              ),
              const LDivider(),
              LButton(
                width: 140,
                shape: LButtonShape.round,
                text: 'toast',
                onTap: () async {
                  handleRun();
                  // toastValue += '111';
                  // LToast.show(
                  //   context,
                  //   position: LToastPosition.center,
                  //   message: toastValue,
                  //   // type: LUIType.success,
                  // );
                },
              ),
              const LDivider(),
              LButton(
                width: 140,
                shape: LButtonShape.round,
                text: 'confirm',
                onTap: () async {
                  String value = '';
                  var res = await LDialog.showConfirmDialog(
                    context,
                    title: '输入框',
                    child: LBox(height: 100, children: [
                      '请输入内容',
                      LBox(
                          marginTop: rpx(10),
                          padding: [rpx(10)],
                          border: const [true],
                          borderRadius: [rpx(4)],
                          borderSide:
                              BorderSide(color: LUI.instance.primaryColor),
                          child: LInput(
                              isDense: true,
                              value: value,
                              onChange: (v) => value = v))
                    ]),
                  );
                  if (res == 0) return;

                  // var res = await LDialog.showConfirmDialog(context,
                  //     title: '确认',
                  //     message: '是否确认此项操作？',
                  //     disabledCloseIcon: false);
                  // print(res);
                },
              ),
              LButton(
                width: 140,
                shape: LButtonShape.round,
                text: 'confirm build',
                onTap: () async {
                  var res = await LDialog.showConfirmDialog(
                    context,
                    disabledMask: true,
                    title: 'child点击',
                    buildChild: (onClose) => LBox(height: 100, children: [
                      '请输入内容',
                      LBox(
                        onTap: () => onClose('hahaha'),
                        marginTop: rpx(10),
                        padding: [rpx(10)],
                        border: const [true],
                        borderRadius: [rpx(4)],
                        borderSide:
                            BorderSide(color: LUI.instance.primaryColor),
                        backgroundColor: Colors.red,
                      )
                    ]),
                  );
                  if (res == 0) return;

                  // var res = await LDialog.showConfirmDialog(context,
                  //     title: '确认',
                  //     message: '是否确认此项操作？',
                  //     disabledCloseIcon: false);
                  // print(res);
                },
              ),
              LDivider(
                text: 'text',
                color: Colors.green,
                space: rpx(20),
                textSpace: rpx(50),
              ),
              LButton(
                // width: 140,
                shape: LButtonShape.round,
                text: 'baseDialog',
                icon: const Icon(
                  Icons.access_alarm_outlined,
                  size: 18,
                  color: Colors.white,
                ),
                onTap: () async {
                  var res = await LDialog.showBaseDialog(
                    child: LBox(
                        height: 100,
                        backgroundColor: Colors.white,
                        children: [
                          '只有一行字',
                          LBox(
                            height: 50,
                            backgroundColor: Colors.red,
                            onTap: () async {
                              if (dialogController != null) {
                                dialogController!.close(11);
                              }
                            },
                          )
                        ]),
                    onCreated: (v) {
                      setState(() {
                        dialogController = v;
                      });
                    },
                  );
                },
              ),
              const LDivider(),
              LButton(
                // width: 140,
                shape: LButtonShape.round,
                text: 'actionDialog',

                onTap: () async {
                  var res = await LDialog.showBottomActionsDialog([
                    LDialogBottomAction(
                        label: '第一项',
                        icon: const Icon(Icons.access_alarm_rounded, size: 18),
                        value: 'first'),
                    LDialogBottomAction(label: '第二项', value: 'two'),
                    LDialogBottomAction(label: '第三项', value: 'three'),
                  ]);
                  // print(res);
                },
              ),
            ],
          ),
        ));
  }
}

//-------------------------------------------------------------------------------------

class OverlayEntryWidget extends StatefulWidget {
  final void Function() onTapNext;
  const OverlayEntryWidget({super.key, required this.onTapNext});

  @override
  _OverlayEntryWidgetState createState() => _OverlayEntryWidgetState();
}

class _OverlayEntryWidgetState extends State<OverlayEntryWidget> {
  int t = 0;
  @override
  Widget build(BuildContext context) {
    return LBox(
      backgroundColor: Colors.red,
      children: [
        LText(
          '$t',
          margin: [rpx(30)],
        ),
        LButton(
          text: '+',
          onTap: () {
            setState(() {
              t++;
            });
          },
        ),
        LButton(
          text: 'add',
          onTap: () async {
            await LDialog.showConfirmDialog(context,
                crossPage: false,
                child: LButton(
                  text: 'to next',
                  onTap: widget.onTapNext,
                ));
          },
        ),
        LButton(
          text: 'next',
          onTap: widget.onTapNext,
        )
      ],
    );
  }
}

//----------------模型定义

class Income extends LStoreModel {
  String? name;

  @override
  Income parse(dynamic data) {
    name = data?['name'];
    return this;
  }

  @override
  Map<String, dynamic> toMap() {
    return {
      'name': name,
    };
  }

  @override
  LStoreModel clone() {
    return Income().parse(toMap());
  }
}
//----------------------------------------------------------------------------

// store 定义

//-------------------------------------------------------------------------

enum ActionType {
  incomeListRequest,
  incomeListSuccess,
  incomeListFailure,
  userNmaeUpdate
}

class IncomeListRequestAction extends Action {
  final bool forceRefresh;
  IncomeListRequestAction({this.forceRefresh = false})
      : super(ActionType.incomeListRequest);
}

class IncomeListSuccessAction extends Action {
  List<Income> results;
  IncomeListSuccessAction(this.results) : super(ActionType.incomeListSuccess);
}

class IncomeListFailureAction extends Action {
  final dynamic error;
  IncomeListFailureAction(this.error) : super(ActionType.incomeListFailure);
}

AppState incomeListRequest(AppState state, IncomeListRequestAction action) {
  var newState = state.clone();
  var incomeList = newState.incomeList;
  incomeList.fetching = true;
  return newState;
}

AppState incomeListSuccess(AppState state, IncomeListSuccessAction action) {
  var newState = state.clone();
  var incomeList = newState.incomeList;
  incomeList.fetching = false;
  incomeList.loaded = true;
  incomeList.results = action.results;
  return newState;
}

AppState incomeListFailure(AppState state, IncomeListFailureAction action) {
  var newState = state.clone();
  var incomeList = newState.incomeList;
  incomeList.fetching = false;
  incomeList.loaded = true;
  incomeList.error = action.error;
  return newState;
}

class UserNameUpdateAction extends Action {
  final String userName;
  UserNameUpdateAction(this.userName) : super(ActionType.userNmaeUpdate);
}

AppState userNameUpdate(AppState state, UserNameUpdateAction action) {
  var newState = state.clone();
  newState.userName = '${newState.userName}+1';
  return newState;
}

incomeListHook(LStore<AppState> store, dynamic action) async {
  if (action.type == ActionType.incomeListRequest) {
    var iaction = action as IncomeListRequestAction;
    List<Income> list = [];
    for (var i = 0; i < 10; i++) {
      list.add(Income()
          .parse({'name': 'force=> ${iaction.forceRefresh} income name: $i'}));
    }
    store.dispatch(IncomeListSuccessAction(list));
    return false;
  }
  return true;
}

class AppState {
  LStoreResultList<Income> incomeList = LStoreResultList();
  String userName = 'test';
  AppState clone() {
    var newState = AppState();
    newState.incomeList = incomeList.clone();
    newState.userName = userName;
    return newState;
  }
}

// 使用

class App {
  LStore<AppState> store = LStore<AppState>(
    initialState: AppState(),
    reducers: {
      ActionType.incomeListRequest: incomeListRequest,
      ActionType.incomeListSuccess: incomeListSuccess,
      ActionType.incomeListFailure: incomeListFailure,
      ActionType.userNmaeUpdate: userNameUpdate
    },
    middleware: [
      storeLogMiddleware,
      incomeListHook,
    ],
  );
}

var app = App();

class SecondPage extends StatefulWidget {
  const SecondPage({super.key});
  @override
  createState() => _SecondPageState();
}

class _SecondPageState extends State<SecondPage> with LStoreMixin {
  LStoreResultList<Income>? incomeList;
  String userName = '';
  @override
  void initState() {
    super.initState();
    handleLoadData(false);
  }

  @override
  void connect(AppState state) {
    if (mounted) {
      LStoreResultList<Income>? value = state.incomeList;
      if (incomeList == null || incomeList?.isEqual(value) != true) {
        setState(() {
          incomeList = value;
        });
      }
      if (state.userName != userName) {
        setState(() {
          userName = state.userName;
        });
      }
    }
  }

  handleLoadData(bool forceRefresh) async {
    app.store.dispatch(IncomeListRequestAction(forceRefresh: false));
    app.store.dispatch(IncomeListRequestAction(forceRefresh: true));
    app.store.dispatch(UserNameUpdateAction('第一次'));
    app.store.dispatch(UserNameUpdateAction('第二次'));
    app.store.dispatch(UserNameUpdateAction('第三次'));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: LText(userName)),
      body: LBox(
        children: [
          LButton(
            text: '加载数据',
            onTap: () => handleLoadData(true),
          ),
          (incomeList?.results ?? []).isEmpty == true
              ? const LText('暂无数据')
              : LBox(
                  children: incomeList!.results.map((e) {
                    return LBox(
                      children: [
                        LText(e.name!),
                      ],
                    );
                  }).toList(),
                ),
        ],
      ),
    );
  }
}

mixin LStoreMixin<T extends StatefulWidget> on State<T> {
  late StreamSubscription<AppState> stream;
  @override
  @mustCallSuper
  void initState() {
    super.initState();
    stream = app.store.change.listen(connect);
    connect(app.store.state);
  }

  void connect(AppState state) {}

  @override
  @mustCallSuper
  void dispose() {
    stream.cancel();
    super.dispose();
  }
}
